home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00072_Script_PalavrasGenerico < prev    next >
Text File  |  1999-03-19  |  10KB  |  344 lines

  1. property sprPaginas  -- Sprite que contem lista de arquivos/paginas
  2. property sprIndicadorScroll -- Sprite com botao de scroll
  3.  
  4. property memMe -- Membro que contem lista
  5. property strPalavraDigitada -- Palavra digitada
  6.  
  7. -- Palavras selecionadas (clicadas)
  8. property intIndicePalavras, intPalavraSelecionada
  9.  
  10.  
  11. -- Ataualizacao da lista
  12. property bBuscando
  13. property intScroll, intLinhas
  14. property strLista, intNovasLinhas
  15. property timeUltimaAtualizacao
  16.  
  17. -- Descricao da Behavior
  18. on getBehaviorDescription
  19.   return "Gerencia lista de palavras"
  20. end
  21.  
  22. on getPropertyDescriptionList
  23.   set p_list = [ ¼
  24.      #sprPaginas: [ #comment:   "Sprite que contem lista de paginas", ¼
  25.                     #format:   #integer, ¼
  26.                     #default:    "" ], ¼
  27.      #sprIndicadorScroll: [ #comment: "Sprite do indicador de scroll", ¼
  28.      #format:   #integer, ¼
  29.      #default:    "" ] ¼
  30.   ]
  31.   return p_list
  32. end
  33.  
  34. -- Inicializacao do sprite
  35. on beginSprite me
  36.   put the member of sprite (the spriteNum of me) into memMe
  37.   put 0 into intScroll
  38.   put 0 into intLinhas
  39.   set the text of field memMe to ""
  40.   put 0 into intPalavraSelecionada
  41.   set strLista to ""
  42.   set intNovasLinhas to 0
  43.   set bBuscando to false
  44. end
  45.  
  46.  
  47. -- Mensagens de scroll
  48. on scrollingUp me
  49.   if intScroll > 0 then 
  50.     scrollByLine member memMe, -1
  51.     put intScroll - 1 into intScroll
  52.     sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  53.   end if
  54.   updateStage
  55.   set tmp = the timer + 20
  56.   repeat while the mouseDown
  57.     if intScroll > 0 and the timer - tmp > 6 then 
  58.       scrollByLine member memMe, -1
  59.       put intScroll - 1 into intScroll
  60.       sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  61.       updateStage
  62.       set tmp = the timer
  63.     end if
  64.     sendAllSprites(#idleSprite)
  65.   end repeat
  66. end 
  67.  
  68. on scrollingDown me
  69.   if intLinhas > 5 and intScroll < intLinhas - 1 then
  70.     scrollByLine member memMe, +1
  71.     put 1 +  intScroll into intScroll
  72.     sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  73.     updateStage
  74.   end if
  75.   set tmp = the timer + 20
  76.   repeat while the mouseDown
  77.     if intLinhas > 5 and intScroll < intLinhas - 1 and the timer - tmp > 6 then
  78.       scrollByLine member memMe, +1
  79.       put 1 +  intScroll into intScroll
  80.       sendSprite(sprIndicadorScroll, #move, intScroll * 10000 / (intLinhas-1))
  81.       updateStage
  82.       set tmp = the timer
  83.     end if
  84.     sendAllSprites(#idleSprite)
  85.   end repeat
  86. end
  87.  
  88. on scrollPaginaCima
  89.   if  intLinhas <= 5 then return
  90.   put intScroll-5 into tmp
  91.   if tmp < 0 then put 0 into tmp
  92.   scrollByLine member memMe, tmp - intScroll
  93.   put tmp into intScroll
  94.   sendSprite(sprIndicadorScroll, #move, intScroll*10000/(intLinhas-1))
  95.   updateStage
  96. end
  97.  
  98. on scrollPaginaBaixo
  99.   if  intLinhas <= 5 then return
  100.   put intScroll+5 into tmp
  101.   if tmp > intLinhas - 1 then put intLinhas - 1 into tmp
  102.   scrollByLine member memMe, tmp - intScroll
  103.   put tmp into intScroll
  104.   sendSprite(sprIndicadorScroll, #move, intScroll*10000/(intLinhas-1))
  105.   updateStage
  106. end  
  107.  
  108. on scrollArraste me, posicao
  109.   if intLinhas <= 5 then return
  110.   put posicao * (intLinhas - 1) / 10000 into tmp
  111.   scrollByLine member memMe, tmp - intScroll
  112.   put tmp into intScroll
  113. end
  114.  
  115. on scrollArrasteFim me
  116.   if intLinhas <= 5 then
  117.     sendSprite(sprIndicadorScroll, #move, 0)
  118.     updateStage
  119.   end if
  120. end
  121.  
  122.  
  123.  
  124. -------------------------------------------------------------------
  125. -------------------------------------------------------------------
  126. -------------------------------------------------------------------
  127. -- Zera lista
  128. on zera me
  129.   put 0 into intScroll
  130.   put 0 into intLinhas
  131.   put 0 into intPalavraSelecionada
  132.   set the text of member memMe to ""
  133.   set strLista to ""
  134.   set intNovasLinhas to 0
  135.   set bBuscando to false
  136.   set the foreColor of member memMe to ¼
  137.       (the backColor of member "FundoPreto")
  138.   set the fontSize of member memMe to¼
  139.       the fontSize of member "TipoLetra"
  140.   set the font of member memMe to¼
  141.       the font of member "TipoLetra"
  142.   sendSprite(sprIndicadorScroll, #move, 0)
  143. end
  144.  
  145. -- Prenche lista com palavras iniciadas com pal
  146. on preenche me, pal
  147.   global gPals, gRefs
  148.   
  149.   -- Limpa listas
  150.   put 0 into intScroll
  151.   put 0 into intLinhas  
  152.   
  153.   sendSprite(sprPaginas, #zera)
  154.   put "" into strLista
  155.   set intNovasLinhas to 0
  156.   put [] into intIndicePalavras
  157.   put 0 into intPalavraSelecionada
  158.   put false into bBuscando
  159.   put 0 into intTamanhoLista
  160.   sendSprite(sprIndicadorScroll, #move, 0)
  161.   
  162.   
  163.   -- Guarda o que a pessoa digitou
  164.   put pal into strPalavraDigitada
  165.   
  166.   -- Se a pessoa nao digitou nada, volta com as
  167.   -- listas vazias
  168.   if strPalavraDigitada = "" then 
  169.     set the text of member memMe to ""
  170.     return
  171.   end if
  172.   
  173.   -- Prepara busca na base de dados
  174.   mSetCriteria(gPals, "canonica", "starts", canoniza(strPalavraDigitada))
  175.   mSelect(gPals)
  176.   
  177.   -- Verifica numero de registros para ler (no maximo 12 a principio)
  178.   put mSelectCount(gPals) into counter
  179.   --  put "PalavrasGenerico: Palavras encontradas: " & counter
  180.   if counter > 12 then
  181.     put 12 into counter 
  182.     put true into bBuscando
  183.   end if
  184.   
  185.   -- Le registros por (teoricamente) 1 segundo
  186.   put the timer into agora
  187.   repeat while (counter > 0) and ((the timer) - agora < 100 )
  188.     if (strLista <> "") then put RETURN after strLista
  189.     
  190.     -- Le do banco de dados
  191.     put mGetField(gPals,"palavra") into newPal
  192.     put mGetField(gPals,"palNum") into indice
  193.     
  194.     -- Acerta indice de palavras
  195.     put the number of words in newPal into tmp
  196.     repeat with i = 1 to tmp
  197.       add intIndicePalavras, indice
  198.     end repeat
  199.     
  200.     -- Acerta lista
  201.     put newPal after strLista
  202.     
  203.     -- Proxima palavra
  204.     mGoNext(gPals)
  205.     put counter - 1 into counter
  206.   end repeat
  207.   
  208.   if counter > 0 then put true into bBuscando
  209.   
  210.   -- Reseta lista de palavras
  211.   global eMac
  212.   
  213.   if eMac then
  214.     trocaTexto memMe, strLista, (the backColor of member "FundoPreto"),¼
  215.           "PalavrasGenerico", "PalavrasGenericoBack"
  216.   else
  217.     set the foreColor of member memMe to ¼
  218.       (the backColor of member "FundoPreto")
  219.     set the text of field memMe to strLista
  220.     set the foreColor of member memMe to ¼
  221.       (the backColor of member "FundoPreto")
  222.   end if
  223.   set intLinhas = the lineCount of member memMe
  224.   put the timer into timeUltimaAtualizacao
  225.   
  226.   -- Atualiza "Stage"
  227.   updateStage
  228. end
  229.  
  230. -- No tempo livre ha duas coisas a serem feitas:
  231. -- . ler sistematicamente o resto dos registros a serem lidos
  232. -- . a cada 100 novos registros ou 3 segundos fazer um "update"
  233. --   na lista de palavras
  234. on idleSprite me
  235.   -- Verifica se e' hora de atualizar lista sendo mostrada
  236.   if (intNovasLinhas >= 100) or ¼
  237.      ((intNovasLinhas > 0) and ¼
  238.      (the timer - timeUltimaAtualizacao > 300)) then
  239.     
  240.     --    put "PalavrasGenerico: idleSprite # tempo passado=" & ¼
  241.     --        the timer - timeUltimaAtualizacao &¼
  242.     --        ", novos items=" & intNovasLinhas
  243.     -- Membro que contem texto
  244.     set the forecolor of member memMe to ¼
  245.         (the backColor of member "FundoPreto")
  246.     set the text of member memMe to strLista
  247.     put the lineCount of member memMe into intLinhas
  248.     if intPalavraSelecionada > 0 and¼
  249.        intPalavraSelecionada <= count(intIndicePalavras) then
  250.       pinta me, intPalavraSelecionada, 3
  251.     end if
  252.     scrollByLine member memMe, intScroll
  253.     set intNovasLinhas to 0
  254.     put the timer into timeUltimaAtualizacao
  255.     sendSprite(sprIndicadorScroll, #move, ¼
  256.     intScroll * 10000 / (intLinhas-1))
  257.     updateStage
  258.   end if
  259.   
  260.   -- Verifica se tem mais registros para buscar
  261.   if bBuscando then  
  262.     -- Le registros por 1 segundo
  263.     put 0 into ret
  264.     put 3 into counter
  265.     put the timer into agora
  266.     
  267.     -- Le registros por 1 segundo
  268.     repeat while (the timer - agora < 100) and (ret = 0) ¼
  269.       and (counter > 0)
  270.       put mGetField(gPals,"palavra") into newPal 
  271.       put mGetField(gPals,"palNum") into indice
  272.       
  273.       -- Acerta indice de palavras
  274.       put the number of words in newPal into tmp
  275.       repeat with i = 1 to tmp
  276.         add intIndicePalavras, indice
  277.       end repeat
  278.       
  279.       -- Acerta lista
  280.       put RETURN & newPal after strLista
  281.       put 1 + intNovasLinhas into intNovasLinhas
  282.       
  283.       -- Vai para proximo
  284.       put mGoNext(gPals)  into ret
  285.       put 1 - counter into counter
  286.     end repeat
  287.     
  288.     -- Se chegou no final para busca
  289.     if ret <> 0 then 
  290.       put false into bBuscando
  291.       put 0 into timeUltimaAtualizacao -- forca atualizacao
  292.     end if
  293.   end if
  294. end
  295.  
  296.  
  297.  
  298. -- Pinta palavras de indice de uma determinada cor
  299. on pinta me, pal, cor
  300.   set the forecolor of word pal of member memMe to cor
  301.   return
  302.   
  303.   put count(intIndicePalavras) into max
  304.   put getAt(intIndicePalavras, pal) into tmp
  305.   if pal < 1 or pal > max then return
  306.   repeat while getAt(intIndicePalavras,pal) = tmp 
  307.     set the forecolor of word pal of member memMe to cor
  308.     put pal + 1 into pal
  309.     if pal > max then exit repeat
  310.   end repeat
  311. end
  312.  
  313. -- Seleciona palavras e lista na lista de paginas
  314. on mouseUp me
  315.   puppetSound 2, "SomCliqueSimples"
  316.   put the mouseWord into mw
  317.   --  put "PalavrasGenerio: mouseUp # " & mw
  318.   if mw < 1 or mw > count(intIndicePalavras) then return
  319.   
  320.   if intPalavraSelecionada > 0 and¼
  321.    intPalavraSelecionada <= count(intIndicePalavras) then
  322.     --    if the platform contains "Mac" then
  323.     set the foreColor of member memMe to ¼
  324.        (the backColor of member "FundoPreto")
  325.     --      set the text of member memMe to¼
  326. --       the text of member memMe
  327.     --    else
  328.     --      pinta me, intPalavraSelecionada, ¼
  329. --            (the backColor of member "FundoPreto")
  330.     --    end if
  331.   end if
  332.   
  333.   put getAt(intIndicePalavras,mw) into tmp
  334.   repeat while getAt(intIndicePalavras,mw) = tmp 
  335.     put mw - 1 into mw
  336.     if mw = 0 then exit repeat
  337.   end repeat
  338.   put mw + 1 into mw
  339.   put mw into intPalavraSelecionada
  340.   pinta me, intPalavraSelecionada, ¼
  341.             (the backColor of member "FundoAzul")
  342.   sendSprite(sprPaginas, #preenche,¼
  343.              getAt(intIndicePalavras,intPalavraSelecionada) )
  344. end